package linearList;

public class TermX {
	public int xexp,coef;
	
	public TermX(int coef,int xexp) {
		this.xexp=xexp;
		this.coef=coef;
	}
	
	public String toString() {
		String str="";
		if(this.coef==0) return str;
		if(this.coef==1) {
			if(this.xexp==0) 
				str="1";
			else {
				if(this.xexp==1) str=str+"x";
				else str+="x^"+this.xexp;
			}
				
		}else if(this.coef==-1) {
			if(this.xexp==0) 
				str="-1";
			else{
				if(this.xexp==1) str=str+"x";
				else str+="x^"+this.xexp;
			}
		}else {
			str=str+this.coef;
			if(this.xexp!=0) 				
			{
				if(this.xexp==1) str=str+"x";
				else str+="x^"+this.xexp;
			}
		}
		return str;
	}
	
	public boolean equalsX(TermX t) {
		if(this.xexp==t.xexp)
			return true;
		else
			return false;
	}
	
	public int compareX(TermX t) {
		if(this.xexp==t.xexp)
			return 0;
		else if(this.xexp>t.xexp)
			return 1;
		else
			return -1;
	}
	
	public void add(TermX t) {
		this.xexp+=t.xexp;
		this.coef+=t.coef;		
	}

}
